package com.itheima.sc.impl.sms;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.sc.api.sms.SmsCouponProductRelationApi;
import com.itheima.sc.mapper.sms.SmsCouponProductRelationMapper;
import com.itheima.sc.pojo.sms.CouponProductCategoryRelation;
import com.itheima.sc.pojo.sms.CouponProductRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsCouponProductRelationImpl implements SmsCouponProductRelationApi {

    @Autowired
    private SmsCouponProductRelationMapper productRelationMapper;

    //添加产品关系表
    public void addProductRelation(List<CouponProductRelation> productRelations) {
        for (CouponProductRelation productRelation : productRelations) {
            productRelationMapper.insert(productRelation);
        }
    }

    //2.删除茶品关系表中的数据
    public void deleteProductRelationByCouponId(Long id) {
        LambdaQueryWrapper<CouponProductRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(id != null, CouponProductRelation::getCouponId, id);
        productRelationMapper.delete(wrapper);
    }


   /* public void updateProductRelation(List<CouponProductRelation> productRelations) {
        for (CouponProductRelation productRelation : productRelations) {
            productRelationMapper.updateById(productRelation);
        }
    }*/

    //查询产品关系表数据
    public List<CouponProductRelation> selectProductRelationByCouponId(Long id) {
        LambdaQueryWrapper<CouponProductRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(id != null, CouponProductRelation::getCouponId, id);
        return productRelationMapper.selectList(wrapper);
    }

    /*//删除产品关系表数据
    public void deleteProductRelation(List<CouponProductRelation> productRelations) {
        productRelationMapper.deleteBatchIds(productRelations);
    }*/
}
